<template>
	<view>
		<view class="m-2 rounded-20 pl-3 mt-2 bg-white" >
			<view class="d-flex j-sb pr-2 py-3" @click="set_api">
				<view class="">当前API</view>
				<view class="d-flex j-center a-center">
					<text class="font text-danger">{{toggle_set}}</text>
					<image src="../../static/images/user/icon_right_arrow.png" mode="" class="icon_right_arrow"></image>
				</view>
			</view>
			<!-- <view class="d-flex j-sb pr-2 py-3 border-bottom" @click="set_langue">
				<view class="">当前语言</view>
				<view class="d-flex j-center a-center">
					<text class="font text-danger">简体中文</text>
					<image src="../../static/images/user/icon_right_arrow.png" mode="" class="icon_right_arrow"></image>
				</view>
			</view> -->
		</view>
		<view class="pl-3 mt-2 bg-white m-2 rounded-20" >
			<view class="d-flex j-sb pr-2 py-3 border-bottom" @click="clear_storage">
				<view class="">清除缓存</view>
				<view class="d-flex j-center a-center">
					<text class="text-light-muted">{{storage=='1B'?"0B":storage}}</text>
					<image src="../../static/images/user/icon_right_arrow.png" mode="" class="icon_right_arrow"></image>
				</view>
			</view>
			<view class="d-flex border-bottom j-sb pr-2 py-3" @click="version_click">
				<view class="">版本信息</view>
				<view class="d-flex j-center a-center">
					<text class="text-light-muted">{{version}}</text>
					<image src="../../static/images/user/icon_right_arrow.png" mode="" class="icon_right_arrow"></image>
				</view>
			</view>
			<view class="d-flex j-sb pr-2 py-3" @click="privacy">
				<view class="">隐私保护指引</view>
				<view class="d-flex j-center a-center">
					<image src="../../static/images/user/icon_right_arrow.png" mode="" class="icon_right_arrow"></image>
				</view>
			</view>
		</view>
		<!--下架 -->
		<u-modal v-model="storage_show" title="提示" :show-title="false"  show-confirm-button show-cancel-button @confirm="storage_confirm">
			<view class="py-3">
				<view class="text-center">共{{storage=='1B'?"0B":storage}}缓存, 是否清除?</view>
			</view>
		</u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				toggle_set:"默认", // API切换
				version:'', // 版本信息
				storage:"", // 缓存
				storage_show:false, // 开关
			}
		},
		methods: {
			change(limit){
				var size = "";
				 if(limit < 0.1 * 1024){                            //小于0.1KB，则转化成B
				    size = limit.toFixed(2) + "B"
				 }else if(limit < 0.1 * 1024 * 1024){            //小于0.1MB，则转化成KB
				     size = (limit/1024).toFixed(2) + "KB"
				 }else if(limit < 0.1 * 1024 * 1024 * 1024){        //小于0.1GB，则转化成MB
				    size = (limit/(1024 * 1024)).toFixed(2) + "MB"
				 }else{                                            //其他转化成GB
				     size = (limit/(1024 * 1024 * 1024)).toFixed(2) + "GB"
				 }
				var sizeStr = size + "";                        //转成字符串
				var index = sizeStr.indexOf(".");                    //获取小数点处的索引
				var dou = sizeStr.substr(index + 1 ,2)            //获取小数点后两位的值
				 if(dou == "00"){                                //判断后两位是否为00，如果是则删除00                
				     return sizeStr.substring(0, index) + sizeStr.substr(index + 3, 2)
				 }
				 return size;		    
			},
			// 切换API
			set_api(){
				uni.navigateTo({
					url:"/pages/login-set-toggle/login-set-toggle"
				})
			},
			// // 切换语言
			// set_langue(){
			// 	uni.navigateTo({
			// 		url:"/pages/login-set-langue/login-set-langue"
			// 	})
			// },
			// 版本信息
			version_click(){
				uni.navigateTo({
					url:"/pages/login-set-version/login-set-version"
				})
			},
			// 隐私保护指引
			privacy(){
				uni.navigateTo({
					url:"/pages/login-set-privacy/login-set-privacy"
				})
			},
			// 缓存开关
			clear_storage(){
				this.storage_show=true
			},
			// 确定清除缓存
			storage_confirm(){
				let storage=uni.getStorageInfoSync()
				uni.clearStorageSync();
				this.storage='0B'
				if(uni.getStorageSync("toggle_default")==false){
					this.toggle_set="默认"
				}
			},
		},
		onShow() {
			if(uni.getStorageSync("toggle_default")){
				this.toggle_set="默认"
				console.log("默认",uni.getStorageSync("toggle_default"))
			}else if(uni.getStorageSync("toggle_demo")){
				this.toggle_set="世联DEMO"
				console.log("世联",uni.getStorageSync("toggle_demo"))
			}	
		},
		onLoad() {
			this.version=this.localConfig.version
			let storage=uni.getStorageInfoSync()
			this.storage=this.change(storage.currentSize)
			console.log(storage)
			
		}
	}
</script>

<style>

</style>
